﻿CREATE TABLE [dbo].[DealOrders] (
    [ID]               INT             IDENTITY (1, 1) NOT NULL,
    [OrderNo]          VARCHAR (255)   NOT NULL,
    [CustomerID]       INT             NOT NULL,
    [NoteDate]         DATETIME        NOT NULL,
    [OperatorUserID]   INT             NOT NULL,
    [CreatedOn]        DATETIME        NOT NULL,
    [TotalMoney]       DECIMAL (18, 5) NOT NULL,
    [Method]           INT             CONSTRAINT [DF__order_dea__Metho__04E4BC85] DEFAULT ('0') NOT NULL,
    [Delivers]         NVARCHAR (200)  NULL,
    [OrderStatus]      INT             NOT NULL,
    [Description]      NVARCHAR (500)  NULL,
    [PaidMoney]        DECIMAL (18, 5) CONSTRAINT [DF_DealOrders_PaidMoney] DEFAULT ((0)) NOT NULL,
    [AssociatedBookID] INT             NULL,
    CONSTRAINT [PK__order_de__3214EC2701142BA1] PRIMARY KEY CLUSTERED ([ID] ASC),
    CONSTRAINT [FK_DealOrders_BookOrders] FOREIGN KEY ([AssociatedBookID]) REFERENCES [invoicing2014].[BookOrders] ([ID]) ON DELETE SET NULL,
    CONSTRAINT [FK_order_deal_customers] FOREIGN KEY ([CustomerID]) REFERENCES [dbo].[Customers] ([ID]),
    CONSTRAINT [FK_order_deal_users] FOREIGN KEY ([OperatorUserID]) REFERENCES [dbo].[Users] ([ID])
);



